package com.magnificent.atlantis.server.ui.panels.common;

import com.magnificent.atlantis.server.database.DataSourceListener;
import com.magnificent.atlantis.server.database.AtlantisDataSource;
import com.magnificent.commons.ui.table.CommonTableModel;

import javax.swing.table.DefaultTableModel;
import java.util.List;

/**
 * ServerUser: Babanin
 * Date: 04.04.2009
 * Time: 12:53:33
 */
public abstract class AbstractTableModel<T> extends CommonTableModel implements DataSourceListener {
    private Class<T> dataClass;

    protected AbstractTableModel(Class<T> dataClass) {
        this.dataClass = dataClass;
        AtlantisDataSource.getInstance().addDataSourceListener(this);
    }

    public void dataChanged(Class clazz) {
        if(clazz.equals(dataClass)){
            updateModel(AtlantisDataSource.getInstance().getBeans(dataClass));
        }
    }

    protected abstract void updateModel(List<T> data);
}
